log using "$Rep_smokelabor/2_analysis/output_logs/appendix_table6.log", replace 

	use "$Rep_smokelabor/1_build/regdata/mortality_county_month.dta", clear 
	local tbl_settings_log format(%6.3f) parentheses(stderr) asterisk()
	local tbl_settings_pmil format(%6.1f) parentheses(stderr) asterisk()

	** panel a, first row
	if 1 {
		reghdfe pmil_nvss_mort1m_age100 hms_deep [aw=seer_pop], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a1.dta", addlabel(outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		
		reghdfe pmil_nvss_mort1m_age60minus hms_deep [aw=seer_pop60minus], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a1.dta", addlabel(outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		
		reghdfe pmil_nvss_mort1m_age60plus hms_deep [aw=seer_pop60plus], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a1.dta", addlabel(outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a1.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			ingap 6
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a1.dta", replace 
		restore 
			
	}
	
	** panel a, second row
	if 1 {
		
		reghdfe pmil_nvss_mort1m_age100 pm25 [aw=seer_pop], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a2.dta", addlabel(outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		
		reghdfe pmil_nvss_mort1m_age60minus pm25 [aw=seer_pop60minus], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a2.dta", addlabel(outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		
		reghdfe pmil_nvss_mort1m_age60plus pm25 [aw=seer_pop60plus], a(fe_cntymoy fe_styr) vce(cluster countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a2.dta", addlabel(outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a2.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			ingap 6
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a2.dta", replace 
		restore 
		
	}
	
	** panel a, third row
	if 1 {

		ivreghdfe pmil_nvss_mort1m_age100 (pm25=hms_deep) [aw=seer_pop], a(fe_cntymoy fe_styr) cluster(countyfip fe_stmos)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		
		ivreghdfe pmil_nvss_mort1m_age60minus (pm25=hms_deep) [aw=seer_pop60minus], a(fe_cntymoy fe_styr) cluster(countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		
		ivreghdfe pmil_nvss_mort1m_age60plus (pm25=hms_deep) [aw=seer_pop60plus], a(fe_cntymoy fe_styr) cluster(countyfip fe_stmos)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a3.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_a3.dta", replace 
		restore 
	
	}
	
	** erase NVSS confidential fields
	foreach var in pmil_nvss_mort1m_age100 pmil_nvss_mort1m_age60plus pmil_nvss_mort1m_age60minus {
		replace `var'=.
	}
	summ
	saveold "$Rep_smokelabor/1_build/regdata/mortality_county_month.dta", replace 
	
	use "$Rep_smokelabor/1_build/regdata/mortality_county_quarter.dta", clear 
	
	** panel b, first row
	if 1 {
		
		reghdfe pmil_nvss_mort1m_age100 hms_deep [aw=seer_pop], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b1.dta", addlabel(outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		
		reghdfe pmil_nvss_mort1m_age60minus hms_deep [aw=seer_pop60minus], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b1.dta", addlabel(outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		
		reghdfe pmil_nvss_mort1m_age60plus hms_deep [aw=seer_pop60plus], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b1.dta", addlabel(outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b1.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			ingap 6
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b1.dta", replace 
		restore 
			
	}
	
	** panel b, second row
	if 1 {
		
		reghdfe pmil_nvss_mort1m_age100 pm25 [aw=seer_pop], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b2.dta", addlabel(outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		sleep 2000
		
		reghdfe pmil_nvss_mort1m_age60minus pm25 [aw=seer_pop60minus], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b2.dta", addlabel(outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		sleep 2000
		
		reghdfe pmil_nvss_mort1m_age60plus pm25 [aw=seer_pop60plus], a(fe_countyqtroy fe_sty) vce(cluster countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b2.dta", addlabel(outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		sleep 2000
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b2.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			ingap 6
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b2.dta", replace 
		restore 
			
	}
	
	** panel b, third row
	if 1 {
		
		ivreghdfe pmil_nvss_mort1m_age100 (pm25=hms_deep) [aw=seer_pop], a(fe_countyqtroy fe_sty) cluster(countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age100 [aw=seer_pop] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(all, `tbl_settings_log') replace
		
		ivreghdfe pmil_nvss_mort1m_age60minus (pm25=hms_deep) [aw=seer_pop60minus], a(fe_countyqtroy fe_sty) cluster(countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60minus [aw=seer_pop60minus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(age60minus, `tbl_settings_log') append
		
		ivreghdfe pmil_nvss_mort1m_age60plus (pm25=hms_deep) [aw=seer_pop60plus], a(fe_countyqtroy fe_sty) cluster(countyfip fe_stqtros)
		summ pmil_nvss_mort1m_age60plus [aw=seer_pop60plus] if e(sample)
		local ymean = `r(mean)'
		regsave using "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b3.dta", addlabel(KleibergenPaap_F, `e(rkf)', outcome_mean, "`ymean'") table(age60plus, `tbl_settings_log') append
		
		preserve 
			use "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b3.dta", replace
			drop if var == "r2"
			drop if var == "_id"
			drop if strpos(var, "_cons_") > 0
			ingap 3
			list , sep(0)
			saveold "$Rep_smokelabor/2_analysis/output_tables/appendix_table6_b3.dta", replace 
		restore 
			
	}
	
	** erase NVSS confidential fields
	foreach var in pmil_nvss_mort1m_age100 pmil_nvss_mort1m_age60plus pmil_nvss_mort1m_age60minus {
		replace `var'=.
	}
	summ
	saveold "$Rep_smokelabor/1_build/regdata/mortality_county_quarter.dta", replace 

log close
